<?php
// +----------------------------------------------------------------------
// |  [ MAKE YOUR WORK EASIER]
// +----------------------------------------------------------------------
// | Copyright (c) 2003-2016 http://www.nbcc.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: fangrenfu <fangrenfu@126.com>
// +----------------------------------------------------------------------

namespace app\all\controller;
use app\common\service\AddCredit;
use app\common\service\R32;
use app\common\service\Score;
use app\common\vendor\Captcha;
use app\common\access\MyAccess;
use app\common\vendor\MultiServer;
use think\Controller;
use think\Db;
use think\Log;

/**各种下拉菜单
 * Class Option
 * @package app\all\controller
 */
class Option {
    public function verify(){
        return Captcha::validimg();
    }
    //角色
    public function role(){
        $result=null;
        try {
            $result=Db::table('roles')->field('role,rtrim(description) as name')->select();
        } catch (\Exception $e) {
            MyAccess::throwException($e->getCode(),$e->getMessage());
        }
        return json($result);
    }
    //获取学院列表 only=0时添加全部选项
    public function school($only=1,$active=0){
        $result=null;
        $condition=null;
        try {
            if($active==1)
                $condition['active']=1;
            $result =Db::table('schools')->order('school')->where($condition)->field('school,rtrim(name) as name')->select();
            if($only==0) {
                $all[] = array('school' => '', 'name' => '全部');
                $result = array_merge($all, $result);
            }
        } catch (\Exception $e) {
            MyAccess::throwException($e->getCode(),$e->getMessage());
        }
        return json($result);
    }
    //获取小图标
    public function icon(){
        $result=null;
        try {
            $result =Db::table('icon')->select();
        } catch (\Exception $e) {
            MyAccess::throwException($e->getCode(),$e->getMessage());
        }
        return json($result);
    }
    //性别
    public function sex(){
        $result=null;
        try {
            $result =Db::table('sexcode')->field('rtrim(code) as sex,rtrim(name) as name')->order('sex')->select();
        } catch (\Exception $e) {
            MyAccess::throwException($e->getCode(),$e->getMessage());
        }
        return json($result);
    }
    public function scorestatus($only=1,$enable=0){
        $result=null;
        $condition=null;
        if($enable!=0) $condition['enable']=1;
        try {
            $result =Db::table('scorestatus')->field('rtrim(name) as name,rtrim(value) as value')->where($condition)->order('name')->select();
            if($only==0) {
                $all[] = array('name' => '', 'value' => '全部');
                $result = array_merge($all, $result);
            }
        } catch (\Exception $e) {
            MyAccess::throwException($e->getCode(),$e->getMessage());
        }
        return json($result);
    }
    public function studentstatus($only=1){
        $result=null;

        try {
            $result = Db::table('statusoptions')->field('name status,rtrim(value) as name')->order('status')->select();
            if($only==0) {
                $all[] = array('status' => '', 'name' => '全部');
                $result = array_merge($all, $result);
            }

        } catch (\Exception $e) {
            MyAccess::throwException($e->getCode(),$e->getMessage());
        }
        return json($result);
    }

    //是否
    public function zo($only=1){
        $result=null;
        try {
            $yes[]=array('zo' => '1', 'name' => '是');
            $no[]=array('zo' => '0', 'name' => '否');
            $result=array_merge($yes,$no);
            if($only==0) {
                $all[] = array('zo' => '', 'name' => '全部');
                $result = array_merge($all, $result);
            }

        } catch (\Exception $e) {
            MyAccess::throwException($e->getCode(),$e->getMessage());
        }
        return json($result);
    }
    //团队类型列表
    public function teamtype($only=1){
        $result=null;
        try {
            $result =Db::table('teamtype')->field('rtrim(name) as name,rtrim(value) as value')->order('name')->select();
            if($only==0) {
                $all[] = array('name' => '', 'value' => '全部');
                $result = array_merge($all, $result);
            }
        } catch (\Exception $e) {
            MyAccess::throwException($e->getCode(),$e->getMessage());
        }
        return json($result);
    }
    /**
     * 测试专用
     */
    public function test(){
        $obj=new Score();
        $row=$obj->getSummary('153%');
        dump($row);
    }

}